/***************************************************************************
 *   Copyright (C) 2009 - 2010 by Simon Qian <SimonQian@SimonQian.com>     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef __VSFUSBH_CDC_H_INCLUDED__
#define __VSFUSBH_CDC_H_INCLUDED__

struct vsfusbh_cdc_t;
struct vsfusbh_cdc_cb_t
{
	vsf_err_t (*on_desc)(struct vsfusbh_cdc_t *cdc,
			struct usb_class_interface_descriptor_t *desc);
	void (*on_event)(struct vsfusbh_cdc_t *cdc);
	void (*on_io)(struct vsfusbh_cdc_t *cdc, bool isin, struct vsfhcd_urb_t *urb);
};

struct vsfusbh_cdc_t
{
	// public
	const struct vsfusbh_cdc_cb_t *cb;
	struct vsf_buffer_t evtbuf;

	// private
	struct vsfusbh_t *usbh;
	struct vsfusbh_device_t *dev;
	struct vsfusbh_ifs_t *ifs;

	struct vsfhcd_urb_t *ctrl_urb;
	struct vsfhcd_urb_t *evt_urb;
	struct vsfhcd_urb_t *in_urb;
	struct vsfhcd_urb_t *out_urb;

	uint8_t comm_iface;
	uint8_t data_iface;

	struct vsfsm_t sm;
	struct vsfsm_pt_t pt;
	struct vsfsm_t in_sm;
	struct vsfsm_t out_sm;
};

vsf_err_t vsfusbh_cdc_init(struct vsfusbh_cdc_t *cdc, struct vsfusbh_t *usbh,
		struct vsfusbh_device_t *dev, struct vsfusbh_ifs_t *ifs);
void vsfusbh_cdc_fini(struct vsfusbh_cdc_t *cdc);
vsf_err_t vsfusbh_cdc_thread(struct vsfsm_pt_t *pt, vsfsm_evt_t evt);

#endif // __VSFUSBH_CDC_H_INCLUDED__
